// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using System;
using System.Linq;
using Elastic.Clients.Elasticsearch.Serialization;

namespace Elastic.Clients.Elasticsearch.IndexLifecycleManagement.Json;

public sealed partial class ActionsConverter : System.Text.Json.Serialization.JsonConverter<Elastic.Clients.Elasticsearch.IndexLifecycleManagement.Actions>
{
	private static readonly System.Text.Json.JsonEncodedText PropAllocate = System.Text.Json.JsonEncodedText.Encode("allocate");
	private static readonly System.Text.Json.JsonEncodedText PropDelete = System.Text.Json.JsonEncodedText.Encode("delete");
	private static readonly System.Text.Json.JsonEncodedText PropDownsample = System.Text.Json.JsonEncodedText.Encode("downsample");
	private static readonly System.Text.Json.JsonEncodedText PropForcemerge = System.Text.Json.JsonEncodedText.Encode("forcemerge");
	private static readonly System.Text.Json.JsonEncodedText PropFreeze = System.Text.Json.JsonEncodedText.Encode("freeze");
	private static readonly System.Text.Json.JsonEncodedText PropMigrate = System.Text.Json.JsonEncodedText.Encode("migrate");
	private static readonly System.Text.Json.JsonEncodedText PropReadonly = System.Text.Json.JsonEncodedText.Encode("readonly");
	private static readonly System.Text.Json.JsonEncodedText PropRollover = System.Text.Json.JsonEncodedText.Encode("rollover");
	private static readonly System.Text.Json.JsonEncodedText PropSearchableSnapshot = System.Text.Json.JsonEncodedText.Encode("searchable_snapshot");
	private static readonly System.Text.Json.JsonEncodedText PropSetPriority = System.Text.Json.JsonEncodedText.Encode("set_priority");
	private static readonly System.Text.Json.JsonEncodedText PropShrink = System.Text.Json.JsonEncodedText.Encode("shrink");
	private static readonly System.Text.Json.JsonEncodedText PropUnfollow = System.Text.Json.JsonEncodedText.Encode("unfollow");
	private static readonly System.Text.Json.JsonEncodedText PropWaitForSnapshot = System.Text.Json.JsonEncodedText.Encode("wait_for_snapshot");

	public override Elastic.Clients.Elasticsearch.IndexLifecycleManagement.Actions Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
	{
		reader.ValidateToken(System.Text.Json.JsonTokenType.StartObject);
		LocalJsonValue<Elastic.Clients.Elasticsearch.IndexLifecycleManagement.AllocateAction?> propAllocate = default;
		LocalJsonValue<Elastic.Clients.Elasticsearch.IndexLifecycleManagement.DeleteAction?> propDelete = default;
		LocalJsonValue<Elastic.Clients.Elasticsearch.IndexLifecycleManagement.DownsampleAction?> propDownsample = default;
		LocalJsonValue<Elastic.Clients.Elasticsearch.IndexLifecycleManagement.ForceMergeAction?> propForcemerge = default;
		LocalJsonValue<Elastic.Clients.Elasticsearch.EmptyObject?> propFreeze = default;
		LocalJsonValue<Elastic.Clients.Elasticsearch.IndexLifecycleManagement.MigrateAction?> propMigrate = default;
		LocalJsonValue<Elastic.Clients.Elasticsearch.EmptyObject?> propReadonly = default;
		LocalJsonValue<Elastic.Clients.Elasticsearch.IndexLifecycleManagement.RolloverAction?> propRollover = default;
		LocalJsonValue<Elastic.Clients.Elasticsearch.IndexLifecycleManagement.SearchableSnapshotAction?> propSearchableSnapshot = default;
		LocalJsonValue<Elastic.Clients.Elasticsearch.IndexLifecycleManagement.SetPriorityAction?> propSetPriority = default;
		LocalJsonValue<Elastic.Clients.Elasticsearch.IndexLifecycleManagement.ShrinkAction?> propShrink = default;
		LocalJsonValue<Elastic.Clients.Elasticsearch.EmptyObject?> propUnfollow = default;
		LocalJsonValue<Elastic.Clients.Elasticsearch.IndexLifecycleManagement.WaitForSnapshotAction?> propWaitForSnapshot = default;
		while (reader.Read() && reader.TokenType is System.Text.Json.JsonTokenType.PropertyName)
		{
			if (propAllocate.TryReadProperty(ref reader, options, PropAllocate, null))
			{
				continue;
			}

			if (propDelete.TryReadProperty(ref reader, options, PropDelete, null))
			{
				continue;
			}

			if (propDownsample.TryReadProperty(ref reader, options, PropDownsample, null))
			{
				continue;
			}

			if (propForcemerge.TryReadProperty(ref reader, options, PropForcemerge, null))
			{
				continue;
			}

			if (propFreeze.TryReadProperty(ref reader, options, PropFreeze, null))
			{
				continue;
			}

			if (propMigrate.TryReadProperty(ref reader, options, PropMigrate, null))
			{
				continue;
			}

			if (propReadonly.TryReadProperty(ref reader, options, PropReadonly, null))
			{
				continue;
			}

			if (propRollover.TryReadProperty(ref reader, options, PropRollover, null))
			{
				continue;
			}

			if (propSearchableSnapshot.TryReadProperty(ref reader, options, PropSearchableSnapshot, null))
			{
				continue;
			}

			if (propSetPriority.TryReadProperty(ref reader, options, PropSetPriority, null))
			{
				continue;
			}

			if (propShrink.TryReadProperty(ref reader, options, PropShrink, null))
			{
				continue;
			}

			if (propUnfollow.TryReadProperty(ref reader, options, PropUnfollow, null))
			{
				continue;
			}

			if (propWaitForSnapshot.TryReadProperty(ref reader, options, PropWaitForSnapshot, null))
			{
				continue;
			}

			if (options.UnmappedMemberHandling is System.Text.Json.Serialization.JsonUnmappedMemberHandling.Skip)
			{
				reader.SafeSkip();
				continue;
			}

			throw new System.Text.Json.JsonException($"Unknown JSON property '{reader.GetString()}' for type '{typeToConvert.Name}'.");
		}

		reader.ValidateToken(System.Text.Json.JsonTokenType.EndObject);
		return new Elastic.Clients.Elasticsearch.IndexLifecycleManagement.Actions(Elastic.Clients.Elasticsearch.Serialization.JsonConstructorSentinel.Instance)
		{
			Allocate = propAllocate.Value,
			Delete = propDelete.Value,
			Downsample = propDownsample.Value,
			Forcemerge = propForcemerge.Value,
#pragma warning disable CS0618
			Freeze = propFreeze.Value
#pragma warning restore CS0618
,
			Migrate = propMigrate.Value,
			Readonly = propReadonly.Value,
			Rollover = propRollover.Value,
			SearchableSnapshot = propSearchableSnapshot.Value,
			SetPriority = propSetPriority.Value,
			Shrink = propShrink.Value,
			Unfollow = propUnfollow.Value,
			WaitForSnapshot = propWaitForSnapshot.Value
		};
	}

	public override void Write(System.Text.Json.Utf8JsonWriter writer, Elastic.Clients.Elasticsearch.IndexLifecycleManagement.Actions value, System.Text.Json.JsonSerializerOptions options)
	{
		writer.WriteStartObject();
		writer.WriteProperty(options, PropAllocate, value.Allocate, null, null);
		writer.WriteProperty(options, PropDelete, value.Delete, null, null);
		writer.WriteProperty(options, PropDownsample, value.Downsample, null, null);
		writer.WriteProperty(options, PropForcemerge, value.Forcemerge, null, null);
#pragma warning disable CS0618
		writer.WriteProperty(options, PropFreeze, value.Freeze, null, null)
#pragma warning restore CS0618
		;
		writer.WriteProperty(options, PropMigrate, value.Migrate, null, null);
		writer.WriteProperty(options, PropReadonly, value.Readonly, null, null);
		writer.WriteProperty(options, PropRollover, value.Rollover, null, null);
		writer.WriteProperty(options, PropSearchableSnapshot, value.SearchableSnapshot, null, null);
		writer.WriteProperty(options, PropSetPriority, value.SetPriority, null, null);
		writer.WriteProperty(options, PropShrink, value.Shrink, null, null);
		writer.WriteProperty(options, PropUnfollow, value.Unfollow, null, null);
		writer.WriteProperty(options, PropWaitForSnapshot, value.WaitForSnapshot, null, null);
		writer.WriteEndObject();
	}
}